package edu.ccut.saturn.manager.systeminfo.core;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;

import edu.ccut.saturn.component.DefaultComponent;
import edu.ccut.saturn.component.IParameterContext;

public class GetSystemInfo extends DefaultComponent {
	@Override
	public void execute(IParameterContext parameterContext) throws Exception {
		

		Properties p = System.getProperties();
		Calendar cl = Calendar.getInstance();
		SimpleDateFormat df = new SimpleDateFormat(Messages.getString("GetSystemInfo.0"),Locale.CHINA); //$NON-NLS-1$
		String date = df.format(cl.getTime());
		Locale locale = Locale.getDefault();
		
		String SystemDate = date;
		String JavaVersion = p.get("java.version").toString(); //$NON-NLS-1$
		String JavaVendor = p.get("java.vendor").toString(); //$NON-NLS-1$
		String JVMVersion = p.get("java.vm.specification.version").toString(); //$NON-NLS-1$
		String JVMVendor = p.get("java.vm.vendor").toString(); //$NON-NLS-1$
		String JVMImplementationVersion = p.get("java.vm.version").toString(); //$NON-NLS-1$
		String JavaRuntime = p.get("java.runtime.name").toString(); //$NON-NLS-1$
		String JavaVM = p.get("java.vm.name").toString(); //$NON-NLS-1$
		String UserTimezone = p.get("user.timezone").toString(); //$NON-NLS-1$
		String UserLocale = locale.getDisplayName();
		String SystemEncoding = p.get("file.encoding").toString(); //$NON-NLS-1$
		String OperatingSystem = p.get("os.name").toString(); //$NON-NLS-1$
		String OSArchitecture = p.get("os.arch").toString(); //$NON-NLS-1$
			
	//	String ApplicationServerContainer = getServletConfig().getServletContext().getServerInfo();
			
		List<String> keyList = new ArrayList<String>(); 

		
		Map<String, String> systemInfos = new HashMap<String, String>();		
		
		systemInfos.put("SystemDate", SystemDate); //$NON-NLS-1$
		systemInfos.put("JavaVersion", JavaVersion); //$NON-NLS-1$
		systemInfos.put("JavaVendor", JavaVendor); //$NON-NLS-1$
		systemInfos.put("JVMVersion", JVMVersion); //$NON-NLS-1$
		systemInfos.put("JVMVendor", JVMVendor); //$NON-NLS-1$
		systemInfos.put("JVMImplementationVersion", JVMImplementationVersion); //$NON-NLS-1$
		systemInfos.put("JavaRuntime", JavaRuntime); //$NON-NLS-1$
		systemInfos.put("JavaVM", JavaVM); //$NON-NLS-1$
		systemInfos.put("UserTimezone", UserTimezone); //$NON-NLS-1$
		systemInfos.put("UserLocale", UserLocale);		 //$NON-NLS-1$
		systemInfos.put("SystemEncoding", SystemEncoding); //$NON-NLS-1$
		systemInfos.put("OperatingSystem", OperatingSystem); //$NON-NLS-1$
		systemInfos.put("OSArchitecture", OSArchitecture); //$NON-NLS-1$
		
		
		
		for(String key : systemInfos.keySet()) {
			keyList.add(key);
		}		
		
		List<Map<String,String>> resultList = new ArrayList<Map<String,String>>();
		
		for(String key : keyList){
			
			Map<String, String> map = new HashMap<String, String>();
			
			map.put("key", key); //$NON-NLS-1$
			map.put("value",systemInfos.get(key)); //$NON-NLS-1$
			
			resultList.add(map);
		}
		
		parameterContext.setParameter(0, resultList);
		
	}
}